import config from "./config";

// 封装
export default (url , data = {} , method = 'GET') => {
  return new Promise((resolve , reject) => {
    wx.request({
      url: config.host + url,
      data ,
      method,
      success: (res) => {
        if(data.isLogin) {
          wx.setStorage({
            key: 'cookies',
            data: res.cookies
          })
        }
        // console.log('请求成功: ' , res);
        resolve(res.data);    /*修改promise的状态为resolve*/
      },
      fail: (err) => {
        console.log('请求失败: ' , err);
        reject(error);      /*修改promise的状态为reject*/
      }
    })
  })
}